{include file="public/admin_head.html"}
<style>
.table{
	width:100%;
}

.table tbody tr td{
	text-align:left;
}

input[type="checkbx"] {
	vertical-align: top;
	margin-left:20px
}
</style>

<body>

	<legend style="margin-top:30px">
		<B>新闻管理列表</B>
		<span style="float:right;margin-right:20px">
			<a href="./index.php?act=news&st=newsAdd" class="btn btn-primary">添加新闻</a>
		</span>
	</legend>
	
     <table>
        <tr>
            <td class="span2" style="text-align: right;">
                <div class="control-group">
                    <label class="control-group" for="fm_searchbox">新闻搜索：</label>
                </div>
            </td>
            <td class="span3">
                <div class="input-append">
               		 <select name="search_type" id="search_type">
				    	<option value="title" {if $smarty.get.search_type == 'title'}selected="selected"{/if}>标题</option>
				    	<option value="content" {if $smarty.get.search_type == 'content'}selected="selected"{/if}>内容</option>				    	
				    </select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <input class="span2" id="txt_keywords" type="text" value="{$keyword}">
                    <button class="btn" type="button" onclick="search();">搜索</button>
                </div>
            </td>
            <td>
         </tr>
    </table>	
	
	
	<table class="table table-bordered table-striped" align="center" style="width:90%">
		<tr>
			<th style="width: 100px;">新闻ID</th>
			<th style="width: 300px;">新闻标题</th>
			<th style="width: 200px;">所属栏目</th>
			<!-- <th style="width: 200px;">是否显示封面</th> -->
			<th style="width:250px">操作</th>
			
		</tr>
{foreach item=news from=$news_list}	
		<tr style="height:49px;">
			<td style="text-align:center">{$news.id}</td>
			<td style="text-align:center"><a href="{if $news.content_source_url}{$news.content_source_url}{else}{$wechat_url}/index.php?act=news&st=info&id={$news.id}{/if}" target="_blank">{$news.title}</a></td>
			<td style="text-align:center"><a href="/index.php?act=news&st=main&category_id={$news.category_id}">{$news.category_name}</a></td>
			<!-- <td style="text-align:center"><a href="javascript:void(0);" class="scroll_flag" newsid="{$news.id}" title="点击修改" flag="{$news.show_cover_pic}" id="list_{$news.id}">{if $news.show_cover_pic}是{else}否{/if}</a></td>-->
			<td style="text-align:center">
				<a class="btn" href="/index.php?act=news&st=newsEdit&id={$news.id}">编辑</a>
				<button class="btn btn-warning" type="button" onclick="checkDel({$news.id});">删除</button>
			</td>
		 </tr>
{/foreach}	
		<table  width="100%">
			<tr>
				<td class="form-actions pagination" align="center">{$pageShow}</td>
			</tr>
		</table>
	</table>		
{include file="public/admin_foot.html"}
<script type="text/javascript">
$(function()
{
	$('.scroll_flag').click(function(){
		var id = $(this).attr("newsid");
		var show_cover_pic = $(this).attr("flag");
		$.ajax({
			data:{'id':id,'show_cover_pic':show_cover_pic},
			url:'/index.php?act=news&st=newsSetCover',
			type:"GET",
			timeout:15000,
			dataType:'json',
			success:function(data) {
				if(typeof data.result != 'undefined' && data.result =='ok') {
					if(show_cover_pic == 1) {
						$("#list_"+id).attr("flag",0);
						$("#list_"+id).html("否");
						
					} else {
						$("#list_"+id).attr("flag",1);
						$("#list_"+id).html("是");
					}
				} else if(typeof data.result != 'undefined' && data.result =='offline') {
					alert("您尚未登录或者登录已超时，请重新登录！");
					window.location.href = '/index.php?act=admin&st=adminLogin';
				}
			},
			error:function(data) {
				alert("系统繁忙，稍后再试！");
			}
		});
	});
});
function checkDel(news_id) {
	if(confirm("你确定要删除这条新闻吗？")) {
		$.ajax({
			data:{'id':news_id},
			url:'/index.php?act=news&st=newsDelete',
			type:"GET",
			timeout:15000,
			dataType:'json',
			success:function(data) {
				if(typeof data.result != 'undefined' && data.result =='ok') {
					window.location.reload();
				} else if(typeof data.result != 'undefined' && data.result =='offline') {
					alert("您尚未登录或者登录已超时，请重新登录！");
					window.location.href = '/index.php?act=admin&st=adminLogin';
				}
			},
			error:function(data) {
				alert("系统繁忙，稍后再试！");
			}
		});
	}
}

function search() {
	var search_type = $("#search_type").val();
	var keywords = $.trim($("#txt_keywords").val());
	window.location.href = "{$host}/index.php?act=news&st=main&search_type="+search_type+"&keyword="+encodeURIComponent(keywords);
}
</script>
